<template>

	<view class="search_show">
		<view class="Search_info">
			<view class="Search">
				<uni-icons type="left" size="25" color="#9d9d9d" @click="goBack()"></uni-icons>
				<u-search placeholder="请输入内容" actionText="取消" v-model="keyword" @custom="goBack()"
					@search="getSearch()"></u-search>
			</view>
			<view class="nav-sort">
				<view class="nav_sort_title">
					<view :class="item.indexValue == 1 ? 'nav_border_color':'' " class="nav_sort_name"
						v-for="(item,index) in searchList">
						<text @click="NavClick(item,index)">{{item.name}}</text>
					</view>
				</view>
			</view>
			<view class="Goods">
				<view class="Goods_show" v-for="(item,index) in GoodsList" :key="index">
					<view class="Goods_image">
						<image :src="item.image"></image>
					</view>
					<view class="Goods_info">
						<view class="Goods_title">
							{{item.storeName}}
						</view>
						<view class="Goods_price">
							￥{{item.price}}
						</view>
						<view class="Goods_fuke">
							<view class="Goods_fuke_price">
								￥{{item.otPrice}}
							</view>
							<view class="Goods_sales">
								{{item.sales}}已售
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				GoodsList: [],
				searchList: [{
					name: '全部',
					indexValue: true,
					toValue: true
				}, {
					name: '销量',
					indexValue: false,
					toValue: false
				}, {
					name: '价格',
					indexValue: false,
					toValue: false
				}],
				keyword: '',
			}
		},
		methods: {
			NavClick(item, index) {
				if (index === 0) {
					this.searchList.forEach(item => item.indexValue = false)
					item.indexValue = true
					item.toValue = true
					this.$http({
						url: '/crmStoreProduct/selCrmStoreProductSearch',
						data: {
							storeName: this.keyword,
							descs: item.toValue,
							priceId: index
						}
					}).then(res => {
						console.log(res)
						this.GoodsList = res.data.data.list
					})
				} else if (index === 1) {
					if (item.toValue === false) {
						this.searchList.forEach(item => item.indexValue = false)
						item.indexValue = true
						item.toValue = true
						this.$http({
							url: '/crmStoreProduct/selCrmStoreProductSearch',
							data: {
								storeName: this.keyword,
								descs: item.toValue,
								priceId: index
							}
						}).then(res => {
							console.log(res)
							this.GoodsList = res.data.data.list
						})
					} else {
						console.log(item.toValue)
						item.toValue = false
						this.$http({
							url: '/crmStoreProduct/selCrmStoreProductSearch',
							data: {
								storeName: this.keyword,
								descs: item.toValue,
								priceId: index
							}
						}).then(res => {
							console.log(res)
							this.GoodsList = res.data.data.list
						})
					}
				} else {
					if (item.toValue === false) {
						this.searchList.forEach(item => item.indexValue = false)
						item.indexValue = true
						item.toValue = true
						this.$http({
							url: '/crmStoreProduct/selCrmStoreProductSearch',
							data: {
								storeName: this.keyword,
								descs: item.toValue,
								priceId: index
							}
						}).then(res => {
							console.log(res)
							this.GoodsList = res.data.data.list
						})
					} else {
						console.log(item.toValue)
						item.toValue = false
						this.$http({
							url: '/crmStoreProduct/selCrmStoreProductSearch',
							data: {
								storeName: this.keyword,
								descs: item.toValue,
								priceId: index
							}
						}).then(res => {
							console.log(res)
							this.GoodsList = res.data.data.list
						})
					}
				}
				// if (item.indexValue === false) {
				// 	this.searchList.map(item => {
				// 		return item.indexValue = false
				// 	})
				// 	this.searchList[index].indexValue = true
				// 	if (item.name === '全部') {
				// 		this.$http({
				// 			url: '/crmStoreProduct/selCrmStoreProductSearch?storeName=',
				// 			method: 'POST',
				// 		}).then(res => {
				// 			this.GoodsList = res.data.data.list
				// 		})
				// 	} else if (item.name === '销量') {
				// 		this.$http({
				// 			url: '/crmStoreProduct/selCrmStoreProductSearch?storeName=',
				// 			method: 'POST',
				// 		}).then(res => {
				// 			let data = res.data.data.list
				// 			let list = data.sort((b, a) => {
				// 				return a.sales - b.sales
				// 			})
				// 			this.GoodsList = ''
				// 			this.GoodsList = list
				// 		})
				// 	} else if (item.name === '时间') {

				// 	} else if (item.name === '价格') {
				// 		this.$http({
				// 			url: '/crmStoreProduct/selCrmStoreProductSearch?storeName=',
				// 			method: 'POST',
				// 		}).then(res => {
				// 			let data = res.data.data.list
				// 			let list = data.sort((a, b) => {
				// 				return a.price - b.price
				// 			})
				// 			this.GoodsList = ''
				// 			this.GoodsList = list
				// 		})
				// 	}
				// }
			},
			goBack() {
				uni.navigateBack({
					delta: 2
				})
			},
			getSearch(storeName) {
				if (storeName == undefined) {
					this.$http({
						url: '/crmStoreProduct/selCrmStoreProductSearch?storeName=',
						method: 'POST',
					}).then(res => {
						this.GoodsList = res.data.data.list
					})
				} else {
					this.$http({
						url: '/crmStoreProduct/selCrmStoreProductSearch?storeName=' + storeName,
						method: 'POST',
					}).then(res => {
						this.GoodsList = res.data.data.list
					})
				}

			},
		},
		onLoad(option) {
			this.keyword = option.value
			this.getSearch(option.value)
		},

	}
</script>

<style scoped>
	@import './search-show.css';
</style>
